package com.wwk.controller;

import com.alibaba.dubbo.config.annotation.Reference;
import com.wwk.constant.MessageConstant;
import com.wwk.entity.PageResult;
import com.wwk.entity.QueryPageBean;
import com.wwk.entity.Result;
import com.wwk.pojo.Member;
import com.wwk.service.MemberService;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

/**
 * @Classname MemberController
 * @Description TODO
 * @Date 2020/11/5 10:03
 * @Created by com.wwk
 * @Author com.wwk
 */
@RestController
@RequestMapping("/member")
public class MemberController {

    @Reference
    private MemberService memberService;

    @RequestMapping("/findPage")
    public PageResult findPage(@RequestBody QueryPageBean pageBean) {
        try {
            PageResult pageResult = memberService.findPage(pageBean);
            return pageResult;
        } catch (Exception e) {
            e.printStackTrace();
            return null;
        }
    }

    @RequestMapping("/findMemById/{memId}")
    public Result findMemById(@PathVariable("memId") Integer memId){

        try{
            Member member=memberService.findMemById(memId);
            return new Result(true, "查询用户成功!",member);
        }catch (Exception e){
            e.printStackTrace();
            return new Result(false,"查询用户失败!");
        }
    }
    @RequestMapping("/edit")
    public Result edit(@RequestBody Member member){
        try{
            memberService.edit(member);
            return new Result(true, MessageConstant.EDIT_MEMBER_SUCCESS);
        }catch (Exception e){
            e.printStackTrace();
            return new Result(true, MessageConstant.EDIT_MEMBER_FAIL);
        }
    }
}
